package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;

import com.ruoyi.system.domain.HouseVo;
import com.ruoyi.system.domain.Surroundings;
import com.ruoyi.system.domain.TbPremisesFacility;
import com.ruoyi.system.domain.TbPremisesInfo;
import com.ruoyi.system.mapper.TbPremisesFacilityMapper;
import com.ruoyi.system.mapper.SPremisesInfoMapper;
import com.ruoyi.system.service.ITbPremisesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 楼盘信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-06-19
 */
@Service
public class SPremisesInfoServiceImpl implements ITbPremisesInfoService
{
    @Autowired
    private SPremisesInfoMapper tbPremisesInfoMapper;

    @Autowired
    private TbPremisesFacilityMapper tbPremisesFacilityMapper;

    /**
     * 查询楼盘信息
     * 
     * @param id 楼盘信息ID
     * @return 楼盘信息
     */
    @Override
    public TbPremisesInfo selectTbPremisesInfoById(Long id)
    {
        return tbPremisesInfoMapper.selectTbPremisesInfoById(id);
    }

    /**
     * 查询楼盘信息列表
     * 
     * @param tbPremisesInfo 楼盘信息
     * @return 楼盘信息
     */
    @Override
    public List<TbPremisesInfo> selectTbPremisesInfoList(TbPremisesInfo tbPremisesInfo)
    {
        return tbPremisesInfoMapper.SelectTbPremisesInfoList(tbPremisesInfo);
    }

    /**
     * 新增楼盘信息
     * 
     * @param houseVo 楼盘信息
     * @return 结果
     */
    @Override
    public int insertTbPremisesInfo(HouseVo houseVo)
    {

        TbPremisesInfo premisesInfo = new TbPremisesInfo();
        //商圈
        String commercialArea = "";
        if(houseVo.getCommercialArea()!=null){

            List<Integer> commercialAreas = houseVo.getCommercialArea();
            System.out.println(commercialAreas);
            for (Integer i:
                 commercialAreas) {
                commercialArea += commercialArea+","+i.toString();
            }
            commercialArea = commercialArea.substring(1);
        }

        //地铁




        //建筑类型
        String buildingType = "";
        if(houseVo.getBuildingType()!=null){
            List<Integer> buildingTypes = houseVo.getBuildingType();
            for (Integer i:
                 buildingTypes) {
                buildingType += buildingType + "," + i.toString();
            }
            buildingType = buildingType.substring(1);
        }

        //物业类型
        String premisesType = "";
        if(houseVo.getPremisesType()!=null) {
            List<Integer> premisesTypes = houseVo.getPremisesType();
            for (Integer i :
                    premisesTypes) {
                premisesType += premisesType + "," + i.toString();
            }
            premisesType = premisesType.substring(1);
        }
        //楼盘特色
        String propertyId = "";
        if(houseVo.getPropertyId()!=null) {
            List<Integer> propertyIds = houseVo.getPropertyId();
            for (Integer i :
                    propertyIds) {
                propertyId += propertyId + "," + i.toString();
            }
            propertyId = propertyId.substring(1);
        }
        //对楼盘信息赋值
        premisesInfo.setName(houseVo.getName());
        premisesInfo.setProvince(houseVo.getProvince());
        premisesInfo.setCity(houseVo.getCity());
        premisesInfo.setCounty(houseVo.getCounty());
        premisesInfo.setCommercialArea(commercialArea);
        premisesInfo.setSubways(houseVo.getSubways());
        premisesInfo.setAddress(houseVo.getAddress());
        premisesInfo.setProportion(houseVo.getProportion());
        premisesInfo.setGrossPlotRatio(houseVo.getGrossPlotRatio());
        premisesInfo.setGreenCoverage(houseVo.getGreenCoverage());
        premisesInfo.setBuildingCount(houseVo.getBuildingCount());
        premisesInfo.setEfficiency(houseVo.getEfficiency());
        premisesInfo.setDeveloper(houseVo.getDeveloper());
        premisesInfo.setEstate(houseVo.getEstate());
        premisesInfo.setIntroduce(houseVo.getIntroduce());
        premisesInfo.setCommunityType(houseVo.getCommunityType());
        premisesInfo.setBuildingType(buildingType);
        premisesInfo.setPremisesType(premisesType);
        System.out.println("asdasdsa====================");
        int i = tbPremisesInfoMapper.insertTbPremisesInfo(premisesInfo);
        System.out.println(i+"楼盘信息");
        Long id = premisesInfo.getId();

        //周边配置
        if(houseVo.getAssortOptions()!=null) {
            List<Surroundings> assortOptions = houseVo.getAssortOptions();
            for (Surroundings s :
                    assortOptions) {
                String title = s.getTitle();
                String value = s.getValue();
                TbPremisesFacility tbPremisesFacility = new TbPremisesFacility();
                tbPremisesFacility.setPremisesId(id);
                tbPremisesFacility.setTitle(title);
                tbPremisesFacility.setContent(value);
                tbPremisesFacility.setType(0);
                int i1 = tbPremisesFacilityMapper.insertTbPremisesFacility(tbPremisesFacility);
                System.out.println(i1+"周边配置");

            }
        }
        //交通情况
        if(houseVo.getTrafficOptions()!=null) {
            List<Surroundings> trafficOptions = houseVo.getTrafficOptions();
            for (Surroundings s :
                    trafficOptions) {
                String title = s.getTitle();
                String value = s.getValue();
                TbPremisesFacility tbPremisesFacility = new TbPremisesFacility();
                tbPremisesFacility.setPremisesId(id);
                tbPremisesFacility.setTitle(title);
                tbPremisesFacility.setContent(value);
                tbPremisesFacility.setType(1);
                int i1 = tbPremisesFacilityMapper.insertTbPremisesFacility(tbPremisesFacility);
                System.out.println(i1+"交通情况");
            }
        }
        return i;
    }

    /**
     * 修改楼盘信息
     * 
     * @param tbPremisesInfo 楼盘信息
     * @return 结果
     */
    @Override
    public int updateTbPremisesInfo(TbPremisesInfo tbPremisesInfo)
    {
        tbPremisesInfo.setUpdateTime(DateUtils.getNowDate());
        return tbPremisesInfoMapper.updateTbPremisesInfo(tbPremisesInfo);
    }

    /**
     * 批量删除楼盘信息
     * 
     * @param ids 需要删除的楼盘信息ID
     * @return 结果
     */
    @Override
    public int deleteTbPremisesInfoByIds(Long[] ids)
    {
        return tbPremisesInfoMapper.deleteTbPremisesInfoByIds(ids);
    }

    /**
     * 删除楼盘信息信息
     * 
     * @param id 楼盘信息ID
     * @return 结果
     */
    @Override
    public int deleteTbPremisesInfoById(Long id)
    {
        return tbPremisesInfoMapper.deleteTbPremisesInfoById(id);
    }
}
